package com.dcw.lixb.designmode.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lixiaobin
 * @date 2020-07-29 15:08:50
 * @desc 描述信息
 */
public class Subject {
    private List<Observer> mObservers = new ArrayList<>();

    public int getState() {
        return state;
    }

    public void setState(int state) {
        boolean change = this.state != state;
        this.state = state;
        if (change) {
            notifyAllObservers();
        }
    }

    private void notifyAllObservers() {
        for (Observer ob : mObservers) {
            ob.update();
        }
    }


    public void attach(Observer observer) {
        mObservers.add(observer);
    }
    private int state;
}
